/*
 * @Author: DaQing Lu
 * @Date: 2020-01-24 14:15:34
 * @LastEditors  : DaQing Lu
 * @LastEditTime : 2020-02-13 14:13:11
 * @Description: file content
 */
import React, {useState, useEffect} from 'react';
import {Button, Table, Tag} from 'antd';
import './SelfBeforeOperatedList.scss';

function SelfBeforeOperatedList(props) {
  const initColumns = [
    {
      title: '订单号',
      dataIndex: 'order_no',
      key: 'order_no'
    },
    // {
    //   title: "供应商",
    //   dataIndex: "vendor_name",
    //   key: "vendor_name"
    // },
    {
      title: '付款时间',
      dataIndex: 'pay_time',
      key: 'pay_time'
    }, {
      title: '付款金额',
      dataIndex: 'goods_price',
      key: 'goods_price'
    }, {
      title: '运费',
      dataIndex: 'freight_price',
      key: 'freight_price'
    }, {
      title: '订单状态',
      key: 'status',
      render: (text, record) => {
        // 订单状态(1已支付订单2已发货订单【部分或者全部发货】3订单完成4未确认收款)
        return <div className='BeforeOperatedAction'>
          {
            text.status === 1 && <Tag size='small' color={'gold'}>已支付订单</Tag>
          }
          {
            text.status === 2 && <Tag size='small' color={'green'}>已发货订单</Tag>
          }
          {
            text.status === 3 && <Tag size='small' color={'blue'}>订单完成</Tag>
          }
          {
            text.status === 4 && <Tag size='small' color={'magenta'}>未确认收款</Tag>
          }
          {
            text.status === 5 && <Tag size='small' color={'#f50'}>订单超时失效</Tag>
          }
        </div>;
      }
    }, {
      title: '操作',
      key: 'action',
      render: (text, record) => {
        // 订单状态(1已支付订单2已发货订单【部分或者全部发货】3订单完成4未确认收款)
        return <div className='BeforeOperatedAction'>
          <Button size='small' type={'primary'} onClick={() => props.showOrderDetails(text.order_no)}>详情</Button>
          {
            text.status === 4 &&
            <Button size='small' type={'danger'} onClick={() => props.confirmCollectMoney(text.order_no)}>确认收款</Button>
          }

          {
            text.invoice_type !== 0 && <Button
              size='small'
              type="primary"
              ghost onClick={() => props.showInvoiceInfo(text.invoice_address_id, text.user_id, text.invoice_type)}
            >发票信息</Button>
          }

          {
            !text.u8acceptadd_order && <Button
              size='small'
              type="danger"
              ghost
              onClick={() => props.showPaymentForm(text.id)}
            > 推收款单到u8</Button>
          }
        </div>;
      }
    }
  ];

  let tempDataSource = [...new Set(props.SelfBeforeOperatedList)];
  const dataSource = tempDataSource.map(item => {
    item.key = item.id;
    return item;
  });
  const [columns, setColumns] = useState(initColumns);
  return (
    <Table dataSource={dataSource} columns={initColumns} pagination={false}/>
  );
}

export default SelfBeforeOperatedList;
